/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hotelsupplymanagement;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Rajasekhar
 */
public class Guisupply {

JButton IGuibutton1,IGuibutton2,IGuibutton3,IGuibutton4,IGuibutton5;
JFrame frame;
JPanel panel1,panel2;
JLabel label1;
JTextArea ta=new JTextArea(15,40);
JScrollPane scrollPane = new JScrollPane(ta);
AddInventory addinv=new AddInventory();
AddProduct addpro=new AddProduct();
//ProductInventory pi=new ProductInventory();
ProductSelected psel=new ProductSelected();

//Variables for file Reading Operation
FileReader frs;
BufferedReader br;



//Variables for inventory
String id[]=new String[20];
String name[]=new String[20],s,s1;
String cline[]=new String[10];
String qua[]=new String[20];
String price[]=new String[20];
String description[]=new String[20];

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Guisupply g=new Guisupply();
    }

    public Guisupply()
    {
       
		frame=new JFrame("SUPPLY CHAIN MANAGEMENT - Noodle House");
		frame.setLayout(new BorderLayout());

		label1=new JLabel("Welcome to Noodle House :");
                label1.setFont(new Font("calibri", Font.BOLD, 29));
                frame.add(label1,BorderLayout.NORTH);

		IGuibutton1=new JButton("View Menu");
		IGuibutton2=new JButton("Inventory Report");
		IGuibutton3=new JButton("Available Inventory Items");
		IGuibutton4=new JButton("Add Menu");
		IGuibutton5=new JButton("Add Inventory Item");
                
                IGuibutton1.addActionListener(new viewProd());
                IGuibutton2.addActionListener(new selProduct());
                IGuibutton3.addActionListener(new viewInv());
                IGuibutton4.addActionListener(new addProd());
                IGuibutton5.addActionListener(new addInv());
                

                frame.add(scrollPane,BorderLayout.CENTER);

         
		
                panel1=new JPanel(new GridLayout(2, 2));
		panel1.add(IGuibutton1);
		panel1.add(IGuibutton2);
		panel1.add(IGuibutton3);
		panel1.add(IGuibutton4);
		panel1.add(IGuibutton5);
                frame.add(panel1,BorderLayout.SOUTH);

                ta.setText("Console Window");
                ta.setBorder(BorderFactory.createLineBorder(Color.black, 1));

                frame.setVisible(true);
		frame.setSize(600,400);
		frame.setLocation(150,150);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	
    }

    class viewProd implements ActionListener {

        public void actionPerformed(ActionEvent event)
        {

             viewProducts();
             ta.append("Opening the menu of Noodle King \n");
        }
        }
    class viewInv implements ActionListener {

        public void actionPerformed(ActionEvent event)
        {
           viewInventory();
           ta.append("Items in Inventory(Kitchen & store room) \n");
        }


        }
    class selProduct implements ActionListener {

        public void actionPerformed(ActionEvent event)
        {
           // pi.displayInventory();
            psel.gettingProduct();
        }
        }
    class addInv implements ActionListener {

        public void actionPerformed(ActionEvent event)
        {
           addinv.addInventory();
        }
        }
    class addProd implements ActionListener {

        public void actionPerformed(ActionEvent event)
        {
            addpro.addProduct();
        }
        }


        /**
         * The function that is used for viewing the available menu  or products
         * in the kitchen
         * It contains the Name,ID,quantity,description and Inventories needed for
         * the particular product
         * @param args
         */
        public void viewProducts()
        {
            ArrayList<GetProducts> pro=new ArrayList<GetProducts>();
            int i=0;
            try
                {
                    frs=new FileReader("GUIProduct.txt");
                    br=new BufferedReader(frs);
                    while((s=br.readLine()) != null)
                        {
                            pro.add(new GetProducts());
                            cline=s.split(",");
                            pro.get(i).setProductName(cline[0]);
                            pro.get(i).setProductId(Integer.parseInt(cline[1]));
                            pro.get(i).setProductQuality(Integer.parseInt(cline[2]));
                            pro.get(i).setProductDescription(cline[3]);
                            pro.get(i).setProductInvList(cline[4]);
                            i++;
                        }

                    Object[] col = new Object[]{"Menu Name","ProductID","Quality","Description","InventoryList"};
                    Object[][] data = {};
                    DefaultTableModel model = new DefaultTableModel(data,col);
                    JTable table = new JTable(model);
                    JScrollPane pane = new JScrollPane(table);

                    for(int n=0;n<i;n++)
                        {
                            //System.out.println("Name :"+p.get(n).getName()+" ID "+p.get(n).getProductid()+" Quality "+p.get(n).getQuantity()+" Description "+p.get(n).getDescription()+" Inventory list "+p.get(n).getInvenlist());
                            Object[] row1=new Object[]{pro.get(n).getProductName(),pro.get(n).getProductId(),pro.get(n).getProductQuality(),pro.get(n).getProductDescription(),pro.get(n).getProductInvList()};
                            model.addRow(row1);
                        }

                    ta.append("Viewing Menu \n");
                    ta.getCursor();
                    JFrame jfp=new JFrame("Menu List");
                    jfp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    jfp.setBackground(Color.white);
                    jfp.setSize(600,300);
                    jfp.setVisible(true);
                    jfp.setLocation(200,200);
                    jfp.add(pane);

                }

		catch(Exception ex)
		{
                    System.out.println("Error in view product");
                }
        }

        /**
         * The function that is used for viewing the Inventory items
         * the store room and Kitchen
         * It contains the Name,ID,quantity,and price of the item
         * @param args
         */
        public void viewInventory()
        {
            ArrayList<GetInventories> inv=new ArrayList<GetInventories>();
            int i=0;
            //int id1[]= new int[20],i=0,lines=0;
            try
                {
                    frs=new FileReader("GUIItem.txt");
                    br=new BufferedReader(frs);
                    while((s1=br.readLine()) != null)
                        {
                            inv.add(new GetInventories());
                            cline=s1.split(",");
                            inv.get(i).setInventoryName(cline[0]);
                            inv.get(i).setInventoryId(Integer.parseInt(cline[1]));
                            inv.get(i).setInventoryQuantity(Integer.parseInt(cline[2]));
                            inv.get(i).setInventoryPrice(Integer.parseInt(cline[3]));
                            i++;
                        }
                    Object[] col = new Object[]{"Name","InventoryID","InventoryQuantity","InventoryPrice"};
                    Object[][] data = {};
                    DefaultTableModel model = new DefaultTableModel(data,col);
                    JTable table = new JTable(model);
                    JScrollPane pane = new JScrollPane(table);

                    for(int n=0;n<i;n++)
                    {
                        //System.out.println("Name :"+q.get(n).getName()+" ID "+q.get(n).getInventoryid()+" Quality "+q.get(n).getQuantity()+" Price "+q.get(n).getPrice());
                        Object[] row1=new Object[]{inv.get(n).getInventoryName(),inv.get(n).getInventoryId(),inv.get(n).getInventoryQuantity(),inv.get(n).getInventoryPrice()};
                        model.addRow(row1);
                    }
                    JFrame jFrameInv=new JFrame("Items in Inventory(Kitchen & store room) ");
                    jFrameInv.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    jFrameInv.setBackground(Color.white);
                    jFrameInv.setSize(600,300);
                    jFrameInv.setVisible(true);
                    jFrameInv.setLocation(200,200);
                    jFrameInv.add(pane);
		}
		catch(Exception ex)
		{
                    System.out.println("Error in inventory");
		}
        }
}
